package uk.org.landeg.euler.problems;

import java.util.ArrayList;
import java.util.Set;
import java.util.TreeSet;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;
import uk.org.landeg.euler.problems.lib.NumbersLib;

public class Problem045 extends AbstractProblem {
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem045());
		launcher.solve();
	}

	@Override
	public Object solve() {
		notes.add("Disgraceful brute force approach, but still solves in ~700ms");
		ArrayList<Long> hits =new ArrayList<Long>();
		Set<Long> T = new TreeSet<Long>();
		Set<Long> P = new TreeSet<Long>();
		Set<Long> H = new TreeSet<Long>();
		for (long n = 1 ; n < 100000 ; n++) {
			T.add(NumbersLib.triangle(n));
			P.add(NumbersLib.pentagonal(n));
			H.add(NumbersLib.hexagonal(n));
		}
		for (long t : T) {
			if (P.contains(t) && H.contains(t)) {
				hits.add(t);
			}
		}
		return hits;
	}

	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return "Find the next triangle number after 40755 that is also pentagonal and hexagonal.";
	}

	@Override
	public Integer getProblemNumber() {
		// TODO Auto-generated method stub
		return 45;
	}
}